﻿#include <iostream>
#include <math.h>
#define Pi acos(-1)     //宏定义Π供后续计算

using namespace std;

class Point             //定义点的类
{
private:
    double x, y;
public:
    Point() {};
    const Point& operator=(const Point& p)
    {
        x = p.x;
        y = p.y;
        return *this;
    }
    Point operator-(const Point& p)         //求两点间距离函数
    {
        Point ans;
        ans.x = x - p.x;
        ans.y = y - p.y;
        return ans;
    }
    double Getx()
    {
        return x;
    }
    double Gety()
    {
        return y;
    }
    friend istream& operator>>(istream& in, Point& p);      //重载 >> 输入
};

class shape                 //定义形状的抽象类
{
public:
    virtual double area() = 0;
};
class circle :public shape      //定义圆的类
{
private:
    Point o;
    double r;
public:
    circle(Point O, double R) :r(R)
    {
        o = O;
    };
    double area()
    {
        cout << "circle" << endl;
        double ans = Pi * r * r;
        return ans;

    };
};
class triangle :public shape    //定义三角形的类
{
private:
    Point p1;
    Point p2;
    Point p3;
public:
    triangle(Point P1, Point P2, Point P3)
    {
        p1 = P1;
        p2 = P2;
        p3 = P3;
    }
    double area()
    {
        cout << "triangle" << endl;
        double ans = abs((p1 - p2).Getx() * (p1 - p3).Gety() - (p1 - p2).Gety() * (p1 - p3).Getx()) / 2;
        return ans;
    };
};
class rectangle :public shape       //定义矩形的类
{
private:
    Point p1;
    Point p2;
public:
    rectangle(Point P1, Point P2)
    {
        p1 = P1;
        p2 = P2;
    }
    double area()
    {
        cout << "rectangle" << endl;
        double ans = abs((p1 - p2).Getx() * (p1 - p2).Gety());
        return ans;
    };
};
int main()
{
    Point p1;
    Point p2[3];
    Point p3[2];
    double R;
    cout << "输入圆心坐标 半径" << endl;
    cin >> p1 >> R;
    cout << "输入三点坐标" << endl;
    cin >> p2[0] >> p2[1] >> p2[2];
    cout << "输入矩形对角两点坐标" << endl;
    cin >> p3[0] >> p3[1];
    circle c(p1, 10);
    triangle t(p2[0], p2[1], p2[2]);
    rectangle r(p3[0], p3[1]);
    shape* s[3] = { &c, &t, &r };
    for (int i = 0; i < 3; i++)
        cout << s[i]->area() << endl;
    return 0;
}

istream& operator>>(istream& in, Point& p)          //重载 >> 输入
{
    in >> p.x >> p.y;
    return in;
};